@extends('cms/system/admin/template/theme_default/common')
@section('page-body')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-sm6 layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <span>合同总额</span>
                        <span class="layui-badge layui-bg-blue layuiadmin-badge">年</span>
                    </div>
                    <div class="layui-card-body layuiadmin-card-list">
                        <p class="layuiadmin-big-font">¥{{$project_amount_year ?? 0}}</p>
                        <p>
                            <span>项目总数</span>
                            <span class="layuiadmin-span-color">{{$project_count_year ?? 0}}个<i class="layui-inline layui-icon layui-icon-flag"></i></span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6 layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <span>本月新签</span>
                        <span class="layui-badge layui-bg-cyan layuiadmin-badge">月</span>
                    </div>
                    <div class="layui-card-body layuiadmin-card-list">
                        <p class="layuiadmin-big-font">33,555</p>
                        <p>
                            <span>新立项目</span>
                            <span class="layuiadmin-span-color">10% <i class="layui-inline layui-icon layui-icon-face-smile-b"></i></span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6 layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <span>全年回款</span>
                        <span class="layui-badge layui-bg-green layuiadmin-badge">年</span>
                    </div>
                    <div class="layui-card-body layuiadmin-card-list">

                        <p class="layuiadmin-big-font">999,666</p>
                        <p>
                            <span>全年支出</span>
                            <span class="layuiadmin-span-color">*** <i class="layui-inline layui-icon layui-icon-dollar"></i></span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6 layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <span>本月回款</span>
                        <span class="layui-badge layui-bg-orange layuiadmin-badge">月</span>
                    </div>
                    <div class="layui-card-body layuiadmin-card-list">

                        <p class="layuiadmin-big-font">66,666</p>
                        <p>
                            <span>本月支出</span>
                            <span class="layuiadmin-span-color">15% <i class="layui-inline layui-icon layui-icon-user"></i></span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header layui-form layui-form-pane layuiadmin-card-header-auto" id="office-search-form" lay-filter="office-search-form">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-sm6 layui-col-md4">
                                <label class="layui-form-label">项目ID</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="number" name="search[id]" value="{{$search['id'] ?? ''}}" placeholder="请输入项目ID" autocomplete="off" />
                            </div>
                        </div>
                            <div class="layui-col-sm6 layui-col-md4">
                                <label class="layui-form-label">项目名称</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" name="search[name]" value="{{$search['name'] ?? ''}}" placeholder="请输入项目名称" autocomplete="off" />
                                </div>
                            </div>
                            <div class="layui-col-sm6 layui-col-md4">
                                <label class="layui-form-label">服务企业</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" name="search[enterprise]" value="{{$search['enterprise'] ?? ''}}" placeholder="请输入企业名称" autocomplete="off" />
                                </div>
                            </div>
                            <div class="layui-col-sm6 layui-col-md4">
                                <label class="layui-form-label">合同金额</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" name="search[amount]" value="{{$search['amount'] ?? ''}}" placeholder="请输入合同金额" autocomplete="off" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body layui-row layui-col-space15">
                        <div class="layui-col-sm12">
                            <table id="office-project-list" lay-filter="office-project-list"></table>
                            <script type="text/html" id="toolbar-office-project-list">
                                <div class="layui-btn-container">
                                    <button class="layui-btn layui-btn-sm" lay-event="createFunc">添加</button>
                                </div>
                            </script>
                            <script type="text/html" id="tool-office-project-list">
                                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detailFunc"><i class="layui-icon layui-icon-release"></i>详情</a>
                                <a class="layui-btn layui-btn-xs" lay-event="moreFunc">更多 <i class="layui-icon layui-icon-down"></i></a>
                            </script>
                            <script type="text/html" id="template-phase">
                                @{{#  if(d.phase == 0) { }}
                                <button class="layui-btn layui-btn-primary layui-btn-xs">商机</button>
                                @{{#  } }}
                                @{{#  if(d.phase == 1) { }}
                                <button class="layui-btn layui-btn-xs">立项</button>
                                @{{#  } }}
                                @{{#  if(d.phase == 2) { }}
                                <button class="layui-btn layui-btn-xs">执行</button>
                                @{{#  } }}
                                @{{#  if(d.phase == 3) { }}
                                <button class="layui-btn layui-btn-xs">收款</button>
                                @{{#  } }}
                                @{{#  if(d.phase == 4) { }}
                                <button class="layui-btn layui-btn-xs">完结</button>
                                @{{#  } }}
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <script type="text/javascript">
        layui.config({
            base: '/layui-admin/'
        }).extend({
            index: 'lib/index'
        }).use(['index', 'system'], function () {
            // 定义操作列表
            var actionList = {
                // 创建
                createFunc: function () {
                    layui.system.iframeLayer({
                        sourceWindow: window,
                        targetName: 'top',
                        title: '添加',
                        content: layui.setter.mvcLink + '/office/admin_project/create?app_id={{$app['id'] ?? 0}}',
                        btn: ['确定', '取消'],
                        yes: function (layerIndex, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-create');
                            submit.click();
                        }
                    });
                },
                // 更新
                updateFunc: function (object) {
                    layui.system.iframeLayer({
                        sourceWindow: window,
                        targetName: 'top',
                        title: '添加',
                        content: layui.setter.mvcLink + '/office/admin_project/update?id=' + object.data.id,
                        btn: ['确定', '取消'],
                        yes: function (layerIndex, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-update');
                            submit.click();
                        }
                    });
                },
                // 详情
                detailFunc: function (object) {
                    var link = layui.setter.mvcLink + '/office/admin_project/detail?id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '项目详情');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 删除
                deleteFunc: function (data) {
                },
                // 回款明细
                receiptRetrieveFunc: function (object) {
                    var link = layui.setter.mvcLink + '/office/admin_receipt/retrieve?app_id={{$app['id'] ?? 0}}&project_id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '回款明细');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 支出明细
                disburseRetrieveFunc: function (object) {
                    var link = layui.setter.mvcLink + '/office/admin_disburse/retrieve?app_id={{$app['id'] ?? 0}}&project_id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '支出明细');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 提成明细
                rewardRetrieveFunc: function (object) {
                    var link = layui.setter.mvcLink + '/office/admin_reward/retrieve?app_id={{$app['id'] ?? 0}}&project_id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '提成明细');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 更多方法
                moreFunc: function (object) {
                    layui.dropdown.render({
                        elem: this,
                        show: true,
                        align: 'right',
                        data: [{
                            id: 'office-project-update',
                            title: '编辑',
                            action: 'updateFunc'
                        }, {
                            id: 'office-receipt-retrieve',
                            title: '回款明细',
                            action: 'receiptRetrieveFunc'
                        }, {
                            id: 'office-disburse-retrieve',
                            title: '支出明细',
                            action: 'disburseRetrieveFunc'
                        }, {
                            id: 'office-reward-retrieve',
                            title: '提成明细',
                            action: 'rewardRetrieveFunc'
                        }, {
                            id: 'office-project-delete',
                            title: '删除',
                            action: 'deleteFunc'
                        }],
                        click: function (dropdownData, dropdownElement) {
                            return actionList[dropdownData.action] ? actionList[dropdownData.action].call(this, object) : '';
                        }
                    });
                },
            };
            // 请求统计
            layui.jquery.ajax({
                url: layui.setter.apiLink + '/office/admin_receipt/count?app_id={{$app['id'] ?? 0}}',
                success: function (result) {
                    console.log(result)
                }
            });
            // 渲染列表
            layui.table.render({
                elem: '#office-project-list',
                toolbar: '#toolbar-office-project-list',
                url: layui.setter.apiLink + '/office/admin_project/retrieve?app_id={{$app['id'] ?? 0}}',
                parseData: function (result) {
                    return {
                        code: result.code == 1 ? 0 : 1,
                        msg: result.msg,
                        count: result.data.total,
                        data: result.data.items
                    }
                },
                cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: 80, title: 'ID', sort: true},
                    {field: 'name', title: '项目名称'},
                    {field: 'amount', title: '项目总额', templet: function (data) { return currency(data.amount, { precision: 0, symbol: '¥' }).format(); }},
                    {field: 'receipt_amount', title: '项目回款', templet: function (data) { return currency(data.receipt_amount, { precision: 0, symbol: '¥' }).format(); }},
                    {field: 'disburse_amount', title: '项目支出', templet: function (data) { return currency(data.disburse_amount, { precision: 0, symbol: '¥' }).format(); }},
                    {field: 'phase', title: '项目进度', templet: '#template-phase', minWidth: 80, align: 'center'},
                    {fixed: 'right', width: 160, title: '操作', align: 'center',  toolbar: '#tool-office-project-list'}
                ]],
                page: true,
                limit: 10,
                limits: [10, 15, 20, 25, 30],
                text: '数据加载异常！'
            });
            // 工具操作
            layui.table.on('toolbar(office-project-list)', function (object) {
                return actionList[object.event] ? actionList[object.event].call(this, object) : '';
            });
            // 列表操作
            layui.table.on('tool(office-project-list)', function (object) {
                return actionList[object.event] ? actionList[object.event].call(this, object) : '';
            });
        });
    </script>
@endsection